import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description: 字典服务器
 */
public class UdpDictServer extends UdpEchoServer{
    private HashMap<String, String> dict = new HashMap<>();

    public UdpDictServer(int port) throws SocketException {
        super(port);
        dict.put("hello", "你好");
        dict.put("wow", "哇");
        dict.put("happy", "开心");
    }

    @Override
    protected String process(String request) {
        String response = dict.getOrDefault(request, "该词无法被翻译");
        return response;
    }

    public static void main(String[] args) throws IOException {
        UdpDictServer udpDictServer = new UdpDictServer(9090);
        udpDictServer.start();
    }
}
